﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Common.Model;
using BLL;
namespace stock.GuPiao
{
    public partial class Active : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["id"] == null)
            {
                Server.Transfer("login.aspx");
                return;
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Session["codes"] == null)
            {
                string script = "<script language='Javascript'>alert('激活码已经过期');location.href='user.aspx';</script>";
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", script);
                return;
            }
            if (Session["id"] == null)
            {
                Server.Transfer("login.aspx");
                return;
            }
            string code = Session["codes"].ToString();
            String enterCode = tbCode.Text.Trim();
            if (code != enterCode)
            {
                string script = "<script language='Javascript'>alert('激活码错误');location.href='user.aspx';</script>";
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", script);
                return;
            }
            CustomerBLL CBL = new CustomerBLL();
            Customer cusModel = CBL.GetModel(int.Parse(Session["id"].ToString()));
            cusModel.Status = 1;
            if (CBL.Update(cusModel))
            {
                string script = "<script language='Javascript'>alert('已经激活');location.href='user.aspx';</script>";
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", script);
            }
        }
    }
}